<% feature_for(:export_archive) do %>
<div class="box export-repository-archive mb-section">
  <div class="box-header">
    <h1 class="title mb-3"><%= t(".Export as Archive") %></h1>
    <div class="text-gray-light">
      <%= t(".Export all docs as markdown files, and archive them into a zip file") %><br/>
      <%= raw t(".This will including a SUMMARY for describe of the Table of contents") %><br/>
      <%= t(".After that you can use many Markdown tools") %> (<a href="https://toolchain.gitbook.com/setup.html" target="_blank" class="link-gray-dark">GitBook</a>, <a href="https://github.com/rust-lang-nursery/mdBook" target="_blank" class="link-gray-dark">mdBook</a>) <%= t(".to genrate it to other format") %>
    </div>
  </div>
  <div class="box-body">
    <% if repository.export_archive_status == "running" %>
      <div class="archive-export-running">
        <p><%= icon_tag("loading") %> <%= t(".Archive of this repository has in generating") %></p>
        <p style="display: none" class="archive-export-retry-message text-gray">
          <%= t(".If you are waiting a long time, you can retry", retry: link_to("retry", repository.to_path("/settings/export?type=archive&force=1"), method: "post", remote: true)) %>
        </p>
      </div>
      <script type="text/javascript">
        // sleep 5s to check status
        window.checkArchiveExportStatus = setInterval(function() {
          $.post("<%= repository.to_path("/settings/export?type=archive&check=1") %>");
        }, 5000);

        // timeout in 25s showup retry message.
        setTimeout(function() {
          $(".archive-export-retry-message").fadeIn();
        }, 25000);

        // clean timer after page exit
        document.addEventListener("turbolinks:before-cache", () => {
          clearInterval(window.checkArchiveExportStatus);
        });
      </script>
    <% elsif repository.archive.attached? %>
      <div class="archive-export-exist">
        <p><%= t(".Archive of this repository was generated") %></p>
        <p><%= t(".Click the button to download it") %></p>
        <div class="form-group">
          <%= link_to t(".Download"), repository.export_url(:archive), target: "_blank", class: "btn btn-download-archive btn-primary" %>

          <%= link_to t(".Generate Again"), repository.to_path("/settings/export?type=archive&force=1"), class: "btn btn-regenerate-archive", method: :post, remote: true, "disable-with": t(".Submiting") %>
        </div>
      </div>
      <script type="text/javascript">
        clearInterval(window.checkArchiveExportStatus);
      </script>
    <% else %>
      <div class="pdf-export-generate">
        <div class="text-gray mb-3"><%= icon_tag("warn") %> <%= t(".Generate Archive will take a long time") %></div>
        <div class="form-group">
          <%= link_to t(".Archive as zip"), repository.to_path("/settings/export?type=archive&force=1"), class: "btn btn-primary btn-submit btn-generate-archive", method: :post, remote: true, "disable-with": t(".Submiting") %>
        </div>
      </div>
    <% end %>
  </div>
</div>
<% end %>